import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:media_kit/media_kit.dart';
import 'package:window_manager/window_manager.dart';
import 'package:media_kit_dome/video/player.dart';

/// 判断当前是否为桌面平台（Windows、Linux、macOS）
bool get _isDesktop => const {
  TargetPlatform.windows,
  TargetPlatform.linux,
  TargetPlatform.macOS,
}.contains(defaultTargetPlatform);

/// 应用程序入口点
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 初始化 media_kit 媒体引擎
  MediaKit.ensureInitialized();

  // 仅在桌面平台初始化窗口管理器
  if (_isDesktop) {
    await windowManager.ensureInitialized();
    const windowOptions = WindowOptions(
      size: Size(1280, 720), // 初始窗口大小
      center: true, // 窗口居中显示
      backgroundColor: Colors.black, // 背景色
      titleBarStyle: TitleBarStyle.normal, // 标题栏样式
    );
    windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.show(); // 显示窗口
      await windowManager.focus(); // 窗口获得焦点
    });
  }

  runApp(const MyApp());
}

/// 主应用程序组件
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Media Kit Fullscreen Demo',
      theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.blue),
      home: const FullscreenVideoPage(),
    );
  }
}
